package com.yc.game.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yc.game.dao.TrainingContentMapper;
import com.yc.game.pojo.TrainingContent;
import com.yc.game.service.TrainingContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TrainingContentServiceImpl implements TrainingContentService {
    @Autowired
    private TrainingContentMapper contentMapper;

    /**
     * 添加代练信息
     * @param content
     * @param email
     * @return
     */
    @Override
    public int add(TrainingContent content, String email) {
        TrainingContent newContent = new TrainingContent();
        newContent.setContent(content.getContent());
        newContent.setLimt(content.getLimt());
        newContent.setMoney(content.getMoney());
        newContent.setStatus(1);
        newContent.setTitle(content.getTitle());
        newContent.setSaleInfo(email);
        return contentMapper.insertSelective(newContent);
    }


    /**
     * 查询所有
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<TrainingContent> getAll(Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<TrainingContent> contents = contentMapper.getAll();
        PageInfo<TrainingContent> contentPageInfo = new PageInfo<>(contents);
        return contentPageInfo;
    }

    /**
     * 修改状态
     * @param trainingId
     */
    @Override
    public void updateStatus(Integer trainingId) {
        TrainingContent trainingContent = new TrainingContent();
        trainingContent.setId(trainingId);
        trainingContent.setStatus(1);
        contentMapper.updateByPrimaryKeySelective(trainingContent);
    }

    /**
     * 查询代练信息
     * @param pageNum
     * @param pageSize
     * @param email
     * @return
     */
    @Override
    public PageInfo<TrainingContent> getByEmail(Integer pageNum, Integer pageSize, String email) {

        PageHelper.startPage(pageNum, pageSize);
        List<TrainingContent> contents = contentMapper.getByEmail(email);
        PageInfo<TrainingContent> contentPageInfo = new PageInfo<>(contents);
        return contentPageInfo;
    }
}
